home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / src / TextCmd.h < prev    next >
C/C++ Source or Header  |  1992-04-29  |  5KB  |  204 lines

  1. #ifndef TextCmd_First
  2. #ifdef __GNUG__
  3. //pragma once
  4. #pragma interface
  5. #endif
  6. #define TextCmd_First
  7.  
  8. #include "TextStyles.h"
  9. #include "TextView.h"
  10.  
  11. class Text;
  12. class StyledText;
  13. class RunArray;
  14.  
  15. typedef void (*TextRangeFP)(Text *t, int at, int *s, int *e);
  16.  
  17. //---- RangeSelector ------------------------------------------------------------
  18.  
  19. extern void CharacterRange(Text *t, int at, int *start, int *end);
  20. extern void WordRange(Text *t, int at, int *start, int *end);
  21. extern void ParagraphRange(Text *t, int at, int *start, int *end);
  22.  
  23. class RangeSelector: public Command {
  24. public:    
  25.     RangeSelector(TextView*, TextRangeFP rf= CharacterRange);
  26.     Command *TrackMouse(TrackPhase, Point, Point, Point);
  27.     virtual void DoPress(SelPoint nextp, int start, int end);
  28.     virtual void DoMove(SelPoint nextp, int start, int end);
  29.  
  30. protected:
  31.     TextView *tv;
  32.     SelPoint startp, endp;
  33.     TextRangeFP range;
  34.     void Range(Text *t, int at, int *from, int *to);
  35. };
  36.  
  37. class ExtendRangeSelector: public RangeSelector {
  38. public:    
  39.     ExtendRangeSelector(TextView*, TextRangeFP rf= CharacterRange); 
  40.     void DoPress(SelPoint nextp, int start, int end);
  41.     void DoMove(SelPoint nextp, int start, int end);
  42.  
  43. private:
  44.     bool swap;
  45.     bool first;
  46. }; 
  47.  
  48. //---- QuickPasteSelector -----------------------------------------------
  49.  
  50. class QuickPasteSelector: public RangeSelector {
  51. public:    
  52.     QuickPasteSelector(TextView*, int, int);
  53.     Command *TrackMouse(TrackPhase, Point, Point, Point);
  54.  
  55. private:
  56.     int from, to;
  57. };
  58.  
  59. //---- DragAndDropSelector -------------------------------------------
  60.  
  61. class DragAndDropSelector: public Command {    
  62. public:    
  63.     DragAndDropSelector(TextView*, int, int, bool paste);
  64.     Command *TrackMouse(TrackPhase, Point, Point, Point);
  65.     void TrackFeedback(Point, Point, bool);
  66. private:
  67.     int from, to, dst;
  68.     TextView *tv;
  69.     Text *t;
  70.     bool moved, paste;
  71.     Point delta;
  72.     static GrCursor oldcursor;
  73.     
  74.     void DrawCaretFeedback(int at);
  75. };
  76.  
  77. //---- TextCommands ----------------------------------------------------------
  78.  
  79. class TextCommand: public Command {
  80. public:  
  81.     MetaDef(TextCommand);      
  82.     TextCommand(TextView*, int cmdNo, char *cmdName, bool saveOldtext= TRUE);
  83.     ~TextCommand();
  84.     void RestoreSelection();    
  85.     void RedoIt();
  86.     
  87. protected:
  88.     TextView *tv;
  89.     Text *oldText;
  90.     int oldStart, oldEnd;
  91. };
  92.  
  93. //---- CutCopyCommand ---------------------------------------------------------
  94.  
  95. class CutCopyCommand: public TextCommand {
  96. public:    
  97.     MetaDef(CutCopyCommand);      
  98.     CutCopyCommand(TextView*, int cmdNo, char *cmdName= 0);
  99.     void DoIt();
  100.     void UndoIt();
  101. };
  102.  
  103. //---- PasteCommand ----------------------------------------------------------
  104.  
  105. class PasteCommand: public TextCommand {
  106. public: 
  107.     MetaDef(PasteCommand);      
  108.     PasteCommand(TextView*, Text*, int cmdNo= cPASTE, char *cmdName= 0);
  109.     ~PasteCommand();
  110.     void DoIt();
  111.     void UndoIt();
  112.  
  113. protected:
  114.     Text *pastetext;
  115.     int newStart, newEnd; 
  116.     bool moved;  
  117. };
  118.  
  119. //---- MoveTextCommand -------------------------------------------------------
  120.  
  121. class MoveTextCommand: public Command {
  122. public:    
  123.     MoveTextCommand(TextView*, int from, int to, int dst);
  124.     ~MoveTextCommand();
  125.     void DoIt();
  126.     void UndoIt();
  127.  
  128. private:
  129.     int from, to, dst;
  130.     TextView *tv;
  131.     Text *mt;
  132. };
  133.  
  134. //---- TypingCommand ---------------------------------------------------------
  135.  
  136. class TypingCommand: public TextCommand {
  137. public:
  138.     
  139.     MetaDef(TypingCommand);
  140.     TypingCommand(TextView *t, int cmdNo, char *cmdName);
  141.     ~TypingCommand();
  142.     void UndoIt();
  143.     void RedoIt();
  144.     void AddChar(int n=1);
  145.     void DelChar();
  146.     
  147. protected:
  148.     Text *backspaceBuf;    // to store text backspaced over 
  149.     Text *newText;
  150.     int newStart;
  151. };
  152.  
  153. //---- CharStyleCommand ----------------------------------------------------
  154.  
  155. class CharStyleCommand: public TextCommand {
  156. public:    
  157.     MetaDef(CharStyleCommand);
  158.     CharStyleCommand(
  159.     TextView *t, int cmdNo, char *cmdName, 
  160.     TxtCharProp mode, const CharStyleSpec &newStyle
  161.     );
  162.     ~CharStyleCommand();
  163.     void DoIt();
  164.     void UndoIt();
  165.     void RedoIt();
  166.     
  167. private:
  168.     RunArray *newStyles, *oldStyles;
  169.     TextView *tvp;
  170.     StyledText *st;
  171.     TxtCharProp mode;
  172.     CharStyleSpec style;    
  173. };
  174.  
  175. //---- ParaStyleCommand ----------------------------------------------------
  176.  
  177. class ParaStyleCommand: public TextCommand {
  178. public:    
  179.     MetaDef(ParaStyleCommand);
  180.     ParaStyleCommand(
  181.     TextView *t, int cmdNo, char *cmdName, 
  182.     TxtParaProp prop, const ParaDesc &newStyle
  183.     );
  184.     ~ParaStyleCommand();
  185.     void DoIt();
  186.     void UndoIt();
  187.     void RedoIt();
  188.     
  189.     TxtParaProp GetNewStyle(ParaDesc &newStyle);
  190.     void Apply(TxtParaProp p, const ParaDesc &newStyle);
  191.     void NotifyWhenDone(EvtHandler *evt);
  192.     
  193. private:
  194.     RunArray *newStyles, *oldStyles;
  195.     TextView *tvp;
  196.     StyledText *st;
  197.     TxtParaProp mode;
  198.     ParaDesc style;
  199.     EvtHandler *notify;
  200.     
  201. };
  202.  
  203. #endif     
  204.